package cn.aposoft.mq.kafka.admin.cluster;

import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.DescribeLogDirsResult;
import org.apache.kafka.clients.admin.LogDirDescription;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.KafkaFuture;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ExecutionException;

public class DescribeLogDirs {
    public static void main(String[] args) {
        Properties p = new Properties();
        p.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "aposoft.cn:10091,aposoft.cn:10092,aposoft.cn:10093");// kafka地址，多个地址用逗号分割
        try (Admin admin = Admin.create(p)) {
            Collection<Integer> brokers = Collections.singleton(91);
            DescribeLogDirsResult result = admin.describeLogDirs(brokers);
            KafkaFuture<Map<Integer, Map<String, LogDirDescription>>> future = result.allDescriptions();
            Map<Integer, Map<String, LogDirDescription>> r = future.get();
            System.out.println(r);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
